package com.xdb.sqlparser.ast.expr;

/**
 * 
 * 二元操作符
 */
public enum SQLBinaryOperator {
	Union("UNION", 0), 
	COLLATE("COLLATE", 20), 
	BitwiseXor("^", 50),
	/**
	 * 乘法
	 */
	Multiply("*", 60), 
	/**
	 * 除法
	 */
	Divide("/", 60), 
	/**
	 * 取余
	 */
	Modulus("%", 60),
	/**
	 * 加法
	 */
	Add("+", 70), 
	/**
	 * 减法
	 */
	Subtract("-", 70),
	/**
	 * 左移
	 */
	LeftShift("<<", 80), 
	/**
	 * 右移
	 */
	RightShift(">>", 80),

	BitwiseAnd("&", 90), 
	BitwiseOr("|", 100),
	/**
	 * 大于
	 */
	GreaterThan(">", 110), 
	/**
	 * 大于等于
	 */
	GreaterThanOrEqual(">=", 110), 
	/**
	 * 是
	 */
	Is("IS", 110), 
	/**
	 * 小于
	 */
	LessThan("<", 110), 
	/**
	 * 小于等于
	 */
	LessThanOrEqual("<=", 110), 
	/**
	 * 
	 */
	LessThanOrEqualOrGreaterThan("<=>", 110), 
	/**
	 * 不等于
	 */
	LessThanOrGreater("<>", 110),
	/**
	 * 模糊查询
	 */
	Like("LIKE", 110), 
	/**
	 * 非模糊查询
	 */
	NotLike("NOT LIKE", 110),

	RLike("RLIKE", 110), 
	NotRLike("NOT RLIKE", 110),
	/**
	 * 不等于
	 */
	NotEqual("!=", 110), 
	NotLessThan("!<", 110), 
	NotGreaterThan("!>", 110), 
	IsNot("IS NOT", 110), 
	/**
	 * 不是
	 */
	Escape("ESCAPE", 110), 
	RegExp("REGEXP", 110), 
	NotRegExp("NOT REGEXP", 110), 
	Equality("=", 110),

	BitwiseNot("!", 130), 
	Concat("||", 140),

	BooleanAnd("AND", 140), 
	BooleanXor("XOR", 150), 
	BooleanOr("OR", 160), 
	Assignment(":=", 169);

	public static int getPriority(SQLBinaryOperator operator) {
		return 0;
	}

	public final String name;
	public final int priority;

	SQLBinaryOperator() {
		this(null, 0);
	}

	SQLBinaryOperator(String name, int priority) {
		this.name = name;
		this.priority = priority;
	}

	public String getName() {
		return this.name;
	}

	public int getPriority() {
		return this.priority;
	}

	public boolean isRelational() {
		switch (this) {
			case Equality :
			case Like :
			case NotEqual :
			case GreaterThan :
			case GreaterThanOrEqual :
			case LessThan :
			case LessThanOrEqual :
			case LessThanOrGreater :
			case NotLike :
			case NotLessThan :
			case NotGreaterThan :
			case RLike :
			case NotRLike :
			case RegExp :
			case NotRegExp :
				return true;
			default :
				return false;
		}
	}

	public boolean isLogical() {
		return this == BooleanAnd || this == BooleanOr || this == BooleanXor;
	}
}
